home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / Nov / di9811gd / Example2 / DllCode.pas < prev    next >
Pascal/Delphi Source File  |  1998-04-25  |  2KB  |  82 lines

  1. unit DllCode;
  2.  
  3. interface
  4.  
  5. uses Windows, Dialogs, SysUtils, Forms;
  6.  
  7. procedure DllShowMessage(Msg: String);
  8.  
  9. { Assume that szResult is at least as long as sz }
  10. procedure GetFirstWord(sz, szResult: PChar); stdcall export;
  11. procedure GetNextWord(sz, szResult: PChar); stdcall export;
  12.  
  13. const
  14.   MessageBoxTitle = 'Dll2';
  15.   CRLF = #13 + #10;
  16.  
  17. implementation
  18.  
  19. threadvar
  20.   gCurrentWordIndex: Integer;
  21.  
  22. procedure DllShowMessage(Msg: String);
  23. begin
  24.   MessageBox(GetDesktopWindow, PChar(Msg), MessageBoxTitle,
  25.              MB_OK or MB_SETFOREGROUND or MB_TASKMODAL);
  26. end;
  27.  
  28. function FindCurrentWord(st: String): String;
  29. var
  30.   Len, j: Integer;
  31. begin
  32.   j := gCurrentWordIndex; Len := Length(st);
  33.   {* Find where the word begins... *}
  34.   while (j <= Len) and
  35.         (not (st[j] in ['A'..'Z','a'..'z','0'..'9'])) do Inc(j);
  36.   gCurrentWordIndex := j;
  37.   {* Find where the word ends... *}
  38.   while (j <= Len) and
  39.         (st[j] in ['A'..'Z','a'..'z','0'..'9']) do Inc(j);
  40.   result := Copy(st, gCurrentWordIndex, j - gCurrentWordIndex + 1);
  41.   gCurrentWordIndex := j;
  42. end;
  43.  
  44. procedure GetFirstWord(sz, szResult: PChar);
  45. var
  46.   st: String;
  47. begin
  48.   gCurrentWordIndex := 1;
  49.   StrPCopy(szResult, FindCurrentWord(String(sz)));
  50. end;
  51.  
  52. procedure GetNextWord(sz, szResult: PChar);
  53. begin
  54.   StrPCopy(szResult, FindCurrentWord(String(sz)));
  55. end;
  56.  
  57. procedure DllEntry(Reason: Integer);
  58. begin
  59.   case Reason of
  60.     DLL_THREAD_ATTACH: begin
  61.       DllShowMessage('Thread attaching. (Thread ID: ' +
  62.                      IntToStr(GetCurrentThreadID) + ')');
  63.     end;
  64.     DLL_THREAD_DETACH: begin
  65.       DllShowMessage('Thread detaching. (Thread ID: ' +
  66.                      IntToStr(GetCurrentThreadID) + ')');
  67.     end;
  68.   end;
  69. end;
  70.  
  71. initialization
  72.  
  73. DllShowMessage('Initializing process-level stuff.');
  74. IsMultiThread := True;
  75. DllProc := @DllEntry;
  76.  
  77. finalization
  78.  
  79. DllShowMessage('Cleaning up process-level stuff.');
  80.  
  81. end.
  82.